﻿using WS.EKA.BusinessModel;
using WS.EKA.BusinessModel.Convertor;
using WS.EKA.DataAccess;
using WS.EKA.Model;
using WS.EKA.ServiceInterface;


namespace WS.EKA.ServiceImpl
{
    public class ApplicationService : BaseService<Application, ApplicationEntity>, IApplicationService
    {
        public ApplicationEntity GetById(int id)
        {
            var application = ApplicationContext.Get(t => t.ApplicationID == id);
            return DBModelToBusinessModel(application);
        }

        public ApplicationEntity GetByCode(string code)
        {
            var application = ApplicationContext.Get(t => t.ApplicationCode == code);
            return DBModelToBusinessModel(application);
        }

        public ApplicationEntity Save(ApplicationEntity entity)
        {
            var application = BusinessModelToDBModel(entity);

            if (application.ApplicationID > 0)
                ApplicationContext.Update(application);
            else
                ApplicationContext.Add(application);
            return DBModelToBusinessModel(application);
        }

       
    }
}
